<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>空调控制</title>
    <script src="util.js"></script>
    <script src="req.js"></script>
    <script src="flexible.min.js"></script>
    <style>
        * {
            padding: 0px;
            margin: 0px;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100vw;
            height: 100vh;
            background-color: #bbb;
        }

        #main {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            width: 35vw;
            height: 80vh;
            background-color: #fff;
            padding: 30px;
        }

        #top {
            display: flex;
            flex: 6;
            align-items: center;
            justify-content: space-around;
            background-color: #ccc;
        }

        #content {
            display: flex;
            flex: 2;
            align-items: center;
            justify-content: space-around;
        }

        #bottom {
            display: flex;
            flex: 2;
            align-items: center;
            justify-content: center;
        }

        #top>img {
            width: 100px;
            height: 100px;
        }

        #bottom img {
            width: 40px;
            height: 40px;
            vertical-align: middle;
        }

        button {
            line-height: 2.5;
            padding: 0px 50px;
            font-size: 20px;
            font-weight: bold;
            background-color: #ccc;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <div id="main">
        <div id="top">
            <img src="./img/cold.png" alt="">
            <img src="./img/hot.png" alt="">
        </div>
        <div id="content">
            <button>冷风</button>
            <button>暖风</button>
        </div>
        <div id="bottom">
            <button><img src="./img/starticon.png" alt=""></button>
        </div>
    </div>
    <script>
        var acOnOff;
        selectAcOnOff(1);
        function selectAcOnOff(id) {
            JQ("http://192.168.1.101:8085/dataInterface/UserWorkEnvironmental/getInfo", { id: id })
                .then(e => {
                    switch (e.data[0].acOnOff) {
                        case 0: $("img").eq(0).attr("src", "./img/cold.png");
                            $("img").eq(1).attr("src", "./img/hot.png");
                            break;
                        case 1: $("img").eq(0).attr("src", "./img/cold1.png");
                            $("img").eq(1).attr("src", "./img/hot.png");
                            break;
                        case 2: $("img").eq(0).attr("src", "./img/cold.png");
                            $("img").eq(1).attr("src", "./img/hot1.png");
                            break;
                    }
                })
        }
        $("button").each((index, item) => {  
            console.log(item); 
                  
            $(item).click(function () {
                switch (index) {
                    case 0: acOnOff = 1;
                        break;
                    case 1: acOnOff = 2;
                        break;
                    case 2: acOnOff = 0;
                        break;
                }
                JQ("http://192.168.1.101:8085/dataInterface/UserWorkEnvironmental/updateAcOnOff",{id:1,acOnOff:acOnOff})
                .then(e=>{
                    selectAcOnOff(1);
                })
            })
        })
    </script>
</body>

</html>